#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,p;
int main() {
    
    cin>>n>>p;

    vector<int> a(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin()+1,a.end());

    int left=1,right=1;
    int ret=0;
    while(right<=n)
    {
        while(left<=right && a[right]-a[left]>2*p)
            left++;
        ret=max(right-left+1,ret);
        right++;
    }
    cout<<ret<<endl;
    return 0;
}


